import { userLogout,userInfo } from "@/api"

const state = {
    userInfo:''
}
const mutations = {
  USERINFO(state,userInfo) {
    state.userInfo = userInfo
  },
  USERLOGOUT(state) {
    localStorage.removeItem('TOKEN')
    state.userInfo =''
  }
}
const actions = {
  //获取用户数据
  async userInfo({commit}) {
    let result = await userInfo()
    if (result.code == 200) {
      commit('USERINFO', result.data)
      return 'ok'
    } else {
      return Promise.reject(new Error('fail'))
    }
  },
  //退出登录接口
 async userLogout({commit}) {
    let result =    await userLogout()
 
    if (result.code == 200) {
      commit('USERLOGOUT')
      return 'ok'
    } else {
      return Promise.reject(new Error('fail'))
    }
  }
}
const getters = {

}
export default {
  state,
  mutations,
  actions,
  getters
}